package com.wyzy.spring.demo;

import com.wyzy.spring.object.Person;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//@Controller
//@ResponseBody
@RestController
@RequestMapping("/demo02")
public class demo02 {
    // 返回数据
    @RequestMapping("/d1")
    public String d1(){
        return "/hello.html";
    }
    // 返回HTML
    @RequestMapping("/d2")
    public String d2(){
        return "<h1>我是html</h1>";
    }
    //返回JSON
    @RequestMapping("/d3")
    public Person d3(){
        Person person = new Person();
        person.setAge(19);
        person.setName("xiaoyang");
        return person;
    }
    // 设置状态码
    @RequestMapping("/d4")
    public String d4(HttpServletResponse response){
        response.setStatus(502);
        return "设置成功";
    }
    //设置Header
    @RequestMapping("/d5")
    public String d5(HttpServletResponse response){
        response.setHeader("Content-Type","text/html;charset=utf-8");
        return "<h1>设置成功</h1>";
    }
    //通过注解设置Header
    @RequestMapping(value = "/d6",produces = "text/html;charset=utf-8")
    public String d6(){
        return "<h1>设置成功</h1>";
    }
    
}
